const io = require('socket.io')();

io.on('connection', (client) => {
    console.log(`${client.id}: new connection`);
    client.on('send', (msg, fn) => {
        console.log('client is subscribing to timer with interval ', msg);
        fn('hei!')
        io.emit('update chat', {msg});
    });

    client.on('disconnect', function(){
        console.log(`${client.id}: user disconnected`);
    });

});

const port = 7999;
io.listen(port);
console.log('chat listening on port ', port);